package com.yj.web.util;

import com.yj.web.util.json.WxGsonBuilder;
import lombok.Data;

import java.io.Serializable;

/**
 * Created by yanlinyang on 2017/9/10.
 */
@Data
public class WxError implements Serializable {

    private static final long serialVersionUID = 7869786563361406291L;

    private int errorCode;

    private String errorMsg;

    private String json;

    public static WxError fromJson(String json) {
        WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
        return error;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    @Override
    public String toString() {
        if (this.json != null) {
            return this.json;
        }
        return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg;
    }


    public static class Builder {
        private int errorCode;
        private String errorMsg;
        public Builder setErrorCode(int errorCode) {
            this.errorCode = errorCode;
            return this;
        }

        public Builder setErrorMsg(String errorMsg) {
            this.errorMsg = errorMsg;
            return this;
        }

        public WxError build() {
            WxError wxError = new WxError();
            wxError.setErrorCode(this.errorCode);
            wxError.setErrorMsg(this.errorMsg);
            return wxError;
        }
    }

}
